<template>
	<view class="container">
		<!-- <view>
			<drag-button :isDock="true" :existTabBar="true" @btnClick="btnClick"></drag-button>
		</view> -->

		<view class="ui-all">
			<!-- 	<view class="avatar" @tap="avatarChoose">
				<view  class="imgAvatar">
					<view class="iavatar" :style="'background: url('+avater+') no-repeat center/cover #eeeeee;'"></view>
				</view>
				<text v-if="avater">修改头像</text>
				<text v-if="!avater">授权微信</text>
				<button v-if="!avater" open-type="getUserInfo" @tap="getUserInfo" class="getInfo"></button>
			</view> -->
			<view class="ui-list">
				<text>辅导员</text>
				<text>{{leave.teacher_name}}</text>
			</view>
			<view class="ui-list">
				<text>姓名</text>
				<text>{{leave.request_name}}</text>
			</view>
			<view class="ui-list">
				<text>电话</text>
				<text>{{leave.phone}}</text>
			</view>
			<view class="ui-list">
				<text>原因</text>
				<textarea @blur="bindTextAreaBlur" auto-height />
			</view>
			<view class="ui-list">
				<text  @click="openStart()">预计开始时间</text><text>{{leave.start_time}}</text>
				<uv-datetime-picker ref="startPick" v-model="start" mode="datetime" @confirm="confirmStart()">
				</uv-datetime-picker>
			</view>
			<view class="ui-list">
				<text  @click="openEnd()">预计结束时间</text><text>{{leave.end_time}}</text>
				<uv-datetime-picker ref="endPick" v-model="end" mode="datetime" @confirm="confirmEnd()">
				</uv-datetime-picker>
			</view>
			<!-- 	<view class="ui-list right">
				<text>常住地</text>
				<picker @change="bindRegionChange" mode='region'>
					<view class="picker">
						{{region[0]}} {{region[1]}} {{region[2]}}
					</view>
				</picker>
			</view> -->
			<!-- 	<view class="ui-list right">
				<text>生日</text>
				<picker mode="date" :value="date" @change="bindDateChange">
					<view class="picker">
						{{date}}
					</view>
				</picker>
			</view> -->
			<!-- <view class="ui-list">
				<text>签名</text>
				<textarea :placeholder="value" placeholder-class="place" :value="description" @input="binddescription"></textarea>
			</view> -->
					<button class="save" @tap="savaInfo">提 交 请 假</button>
		</view>
	</view>
</template>


<script>
	import dragButton from "@/components/drag-button/drag-button.vue";
	export default {
		components: {
			dragButton
		},
		data() {
			return {
				open_id:"",
				leave: {
					request_id:"",
					request_name:"",
					request_class_id:"",
					request_class_name:"",
					start_time:"",
					end_time:"",
					msg:"",
					teacher_id:"",
					teacher_name: "",
					request_name: "",
					action:"学生请求",
					phone:"",
				},
				pppp:"      ",
				start: Number(new Date()),
				end:Number(new Date()),
			}
		},
		methods: { // 获得open_id
			// 获得open_id
			getOpenid: function() {
				let that = this
				uni.login({
					provider: "weixin",
					success: function(res) {
						that.$myHttp({
							url: '/wx/openid',
							method: "post",
							data: {
								"code": res.code,
							}
						}).then((res) => {
							var result = res.data
							uni.setStorageSync('open_id', result.data.open_id)
							uni.setStorageSync('session_key', result.data.session_key)
						})
					},
				});
				this.open_id = uni.getStorageSync('open_id');
			},
			Timestamp:function(timeStr){
					let date = new Date(timeStr);  // 参数需要毫秒数，所以这里将秒数乘于 1000
				let	Y = date.getFullYear() + '-';
				let	M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
				let	D = date.getDate() + ' ';
				let	h = date.getHours() + ':';
				let	m = date.getMinutes() + ':';
				let	s = date.getSeconds(); 
					return Y+M+D+h+m+s
			},
			openStart() {
				this.$refs.startPick.open();
			},
			openEnd() {
				this.$refs.endPick.open();
			},
			confirmStart(e) {
				this.leave.start_time = this.Timestamp(this.start)
			},
			confirmEnd(e) {
				this.leave.end_time = this.Timestamp(this.end)
			},
			bindTextAreaBlur(e){
				this.leave.msg=e.detail.value
			},
			savaInfo:function(){
				let that = this
				if  (this.leave.msg==""){
					uni.showToast({
						title: "原因不能为空",
						duration: 3000,
						icon: 'none'
					})
					return
				}
				if  (this.leave.start_time==""){
					uni.showToast({
						title: "开始时间不能为空",
						duration: 3000,
						icon: 'none'
					})
					return
				}
				if  (this.leave.end_time==""){
					uni.showToast({
						title: "结束时间不能为空",
						duration: 3000,
						icon: 'none'
					})
					return
				}
				// console.log(this.leave)
				this.$myHttp({
					url: '/leave/student/create',
					method: "post",
					data: that.leave
				}).then((res)=>{
					let result = res.data
					if (result.code==1000){
						uni.showToast({
							title: "操作成功",
							duration: 3000,
							icon: 'none'
						})
						// 登录成功跳转到个人
						uni.switchTab({
							url: '/pages/home/home'
						})
						return
					}
					uni.showToast({
						title: result.msg,
						duration: 3000,
						icon: 'none'
					})
				})
			},
			// 获得用户的详细信息
			getInfoPeople: function() {
				let that = this
				this.$myHttp({
					url: '/student/search/openid',
					method: "post",
					data: {
						"open_id": this.open_id,
					}
				}).then((res) => {
					//获取信息
					let result = res.data.data
					that.leave.request_class_id=result.class_id
					that.leave.request_class_name=result.class_name
					that.leave.request_name=result.name
					that.leave.phone=result.phone
					that.leave.teacher_id=result.teacher_id
					that.leave.request_id=result.wx_open_id
					that.leave.teacher_name=result.teacher_name
				})
			},
		},
		created() {
			//获得open_id
			this.open_id = uni.getStorageSync('open_id');
			this.getInfoPeople()
		}
	}
</script>

<style lang="less">
	.container {
		display: block;
	}

	.ui-all {
		padding: 20rpx 40rpx;

		.avatar {
			width: 100%;
			text-align: left;
			padding: 20rpx 0;
			border-bottom: solid 1px #f2f2f2;
			position: relative;

			.imgAvatar {
				width: 140rpx;
				height: 140rpx;
				border-radius: 50%;
				display: inline-block;
				vertical-align: middle;
				overflow: hidden;

				.iavatar {
					width: 100%;
					height: 100%;
					display: block;
				}
			}

			text {
				display: inline-block;
				vertical-align: middle;
				color: #8e8e93;
				font-size: 28rpx;
				margin-left: 40rpx;
			}

			&:after {
				content: ' ';
				width: 20rpx;
				height: 20rpx;
				border-top: solid 1px #030303;
				border-right: solid 1px #030303;
				transform: rotate(45deg);
				-ms-transform: rotate(45deg);
				/* IE 9 */
				-moz-transform: rotate(45deg);
				/* Firefox */
				-webkit-transform: rotate(45deg);
				/* Safari 和 Chrome */
				-o-transform: rotate(45deg);
				position: absolute;
				top: 85rpx;
				right: 0;
			}
		}

		.ui-list {
			width: 100%;
			text-align: left;
			padding: 20rpx 0;
			border-bottom: solid 1px #f2f2f2;
			position: relative;

			text {
				color: #4a4a4a;
				font-size: 28rpx;
				display: inline-block;
				vertical-align: middle;
				min-width: 150rpx;
			}

			input {
				color: #030303;
				font-size: 30rpx;
				display: inline-block;
				vertical-align: middle;
			}

			button {
				color: #030303;
				font-size: 30rpx;
				display: inline-block;
				vertical-align: middle;
				background: none;
				margin: 0;
				padding: 0;

				&::after {
					display: none;
				}
			}

			picker {
				width: 90%;
				color: #030303;
				font-size: 30rpx;
				display: inline-block;
				vertical-align: middle;
				position: absolute;
				top: 30rpx;
				left: 150rpx;
			}

			textarea {
				color: #030303;
				font-size: 30rpx;
				vertical-align: middle;
				height: 150rpx;
				width: 100%;
				margin-top: 50rpx;
			}

			.place {
				color: #999999;
				font-size: 28rpx;
			}
		}

		.right:after {
			content: ' ';
			width: 20rpx;
			height: 20rpx;
			border-top: solid 1px #030303;
			border-right: solid 1px #030303;
			transform: rotate(45deg);
			-ms-transform: rotate(45deg);
			/* IE 9 */
			-moz-transform: rotate(45deg);
			/* Firefox */
			-webkit-transform: rotate(45deg);
			/* Safari 和 Chrome */
			-o-transform: rotate(45deg);
			position: absolute;
			top: 40rpx;
			right: 0;
		}

		.save {
			background: #030303;
			border: none;
			color: #ffffff;
			margin-top: 40rpx;
			font-size: 28rpx;
		}
	}
</style>